<?php
	if(!isset($_REQUEST['ajax'])){ $_REQUEST['ajax'] = "";}
	if($_REQUEST['ajax']!=true) include 'header.tpl.php';
	include 'task_panel.tpl.php';
?>
	<div class="row">
		<div class="col-lg-12">
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="icon-cog"></i> <?php echo $this->language['task_create'];?></div>
				</div>
				<div class="panel-body">
					<form action="javascript:taoTask();" class="form-horizontal">
						<div class="form-group">
							<label class="col-lg-2 control-label"><?php echo $this->language['task_name'];?></label>
							<div class="col-lg-6">
								<input type="text" id="taskName" name="taskName" class="form-control" />
							</div>
						</div>
						<?php if(count($this->project) == 0):?>
						<div class="form-group">
							<label class="col-lg-2 control-label"><?php echo $this->language['task_type'];?></label>
							<div class="col-lg-4">
								<select name="taskType" id="taskType" class="form-control">
									<option><?php echo $this->language['choose'];?></option>
									<option value="1"><?php echo $this->language['task_project_type'];?></option>
									<option value="0"><?php echo $this->language['task_request_type'];?></option>
								</select><br/>
								<select class="form-control" name="proName" style="display:none;" id="proName"></select>
								<select class="form-control" name="subproName" style="display:none;" id="subproName"></select>
							</div>
						</div>
						<?php else:?>
						<div class="form-group">
							<label class="col-lg-2 control-label"><?php echo $this->language['project'];?></label>
							<div class="col-lg-6">
								<input type="hidden" id="taskType" name="taskType" value="1" />
								<input type="hidden" id="proName" name="proName" value="<?php echo $this->project['pId'];?>" />
								<input type="text" value="<?php echo $this->project['pName'];?>" class="form-control" disabled />
							</div>
						</div>
						<?php endif;?>
						<div class="form-group" id="tnn">
							<label class="col-lg-2 control-label"><?php echo $this->language['receiver'];?></label>
							<div class="col-lg-4">
								<select name="receiver[]" id="receiver" multiple class="form-control" style="height:150px;">
									<?php foreach($this->receiver as $row): ?>
									<option value="<?php echo $row['uId'];?>"><?php echo $_SESSION['user_data'][$row['uId']]['fullname'];?></option>
									<?php endforeach;?>
								</select>
							</div>
						</div>
						<div class="form-group" id="cvp" style="display:none;">
							<label class="col-lg-2 control-label">Công việc Yêu cầu</label>
							<div class="col-lg-4">
								<select name="parent" id="parent" class="form-control"></select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-lg-2 control-label"><?php echo $this->language['task_start_date'];?></label>
							<div class="col-lg-2">
								<input type="text" id="datepicker1" name="taskStart" class="form-control" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-lg-2 control-label"><?php echo $this->language['task_end_date'];?></label>
							<div class="col-lg-2">
								<input type="text" id="datepicker" name="taskDead" class="form-control" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-lg-2 control-label"><?php echo $this->language['attach_file'];?></label>
							<div class="col-lg-6">
								<div id="file-uploader"></div>
								<input type=hidden id="uploadfile" name="uploadfile" value="<?php if(isset($this->fileht)){foreach($this->fileht as $f){if($f!="") echo ';'.$f;}} ?>">
								<div id="uploaded"></div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-lg-2 control-label"><?php echo $this->language['task_content'];?></label>
							<div class="col-lg-10">
								<textarea class="form-control wysiwyg" id="textarea" name="taskContent" rows="5" wrap="off"></textarea>
							</div>
						</div>
						<div class="form-group">
							<div class="col-lg-offset-2 col-lg-10">
								<button type="submit" data-loading-text="Loading..." class="btn btn-primary"><?php echo $this->language['accept'];?></button>
								<button type="reset" class="btn btn-danger">Reset</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<link href="resources/css/fileuploader.css" type="text/css" rel="stylesheet" />
	<script type="text/javascript" src="resources/scripts/jquery-ui.min.js"></script>
	<script type="text/javascript" src="resources/scripts/jquery.datePicker.js"></script>
	<script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>
	<script type="text/javascript" src="resources/scripts/fileuploader.js"></script>
	<script type="text/javascript">
	$(function(){
	  $("#taskType").change(function(){
		if($(this).val()==0){
			$("#receiver").html('');
			$.getJSON("?func=task_ajax",{type: $(this).val()}, function(data){
			  var selectm = $('#receiver');
                $.each(data, function (key, cat) {
				var group = $('<optgroup>',{label:key});
				$.each(cat,function(i,item) {
					$("<option/>",{value:item.optval,text:item.optdis}).appendTo(group);
				});
				group.appendTo( selectm );
			});

			  $("#tnn").attr("style", "display:block");
			  $("#proName").attr("style", "display:none");
			  $("#subproName").attr("style", "display:none");
			  $("#proName").html('');
			  $("#subproName").html('');
			})
		}
		else if($(this).val()==1){
			$.getJSON("?func=task_ajax",{type: $(this).val()}, function(j){
			  var options = '';
			  for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			  }
			  $("#tnn").attr("style", "display:none");
			  $("#proName").attr("style", "display:block");
			  $("#proName").html(options);
			  $("#receiver").html('');
			})
		}
	  })
	});
	$(function(){
	  $("#proName").change(function(){
		$.getJSON("?func=task_ajax",{type: '1',pid: $(this).val()}, function(j){
		  var options = '';
		  for (var i = 0; i < j.length; i++) {
			options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		  }
		  $("#tnn").attr("style", "display:block");
		  $("#receiver").html(options);
		});
		$.getJSON("?func=task_ajax",{type: '2',pid: $(this).val()}, function(j){
		  var options = '';
		  for (var i = 0; i < j.length; i++) {
			options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		  }
		  $("#cvp").attr("style", "display:block");
		  $("#parent").html(options);
		});
		$.getJSON("?func=task_ajax",{type: '3',pid: $(this).val()}, function(j){
		  if(j.length > 1){
		  	var options = '';
			for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
			$("#subproName").attr("style", "display:block");
			$("#subproName").html(options);
		  }
		});
	  });
	  $("#subproName").change(function(){
	  	if($(this).val() == 0){
	  		$.getJSON("?func=task_ajax",{type: '1',pid: $("#proName").val()}, function(j){
			  var options = '';
			  for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			  }
			  $("#tnn").attr("style", "display:block");
			  $("#receiver").html(options);
			});
			$.getJSON("?func=task_ajax",{type: '2',pid: $("#proName").val()}, function(j){
			  var options = '';
			  for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			  }
			  $("#cvp").attr("style", "display:block");
			  $("#parent").html(options);
			});
	  	}
	  	else{
		  	$.getJSON("?func=task_ajax",{type: '1',pid: $(this).val()}, function(j){
			  var options = '';
			  for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			  }
			  $("#tnn").attr("style", "display:block");
			  $("#receiver").html(options);
			});
			$.getJSON("?func=task_ajax",{type: '2',pid: $(this).val()}, function(j){
			  var options = '';
			  for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			  }
			  $("#cvp").attr("style", "display:block");
			  $("#parent").html(options);
			});
		}
	  });
	});
	$(function() {
		$( "#datepicker1" ).datepicker({dateFormat: 'dd-mm-yy'});
		$( "#datepicker" ).datepicker({dateFormat: 'dd-mm-yy'});
	});
	$(".wysiwyg").wysiwyg();
	var uploader = new qq.FileUploader({
		element: document.getElementById('file-uploader'),
		action: 'file.php?act=upload',
		debug: false
	});
	</script>
<?php if(isset($this->breadcrumb) && isset($this->title_header)):?>
	<script type="text/javascript">
		$(function() {
			$("#title-header").text('<?php echo $this->title_header;?>');
			$("#breadcrumb").html('<?php echo build_breadcrumb($this->breadcrumb);?>');
		});
	</script>
<?php endif;?>
<?php
	if($_REQUEST['ajax']!=true) include 'footer.tpl.php';
?>